# -*- coding:utf-8 -*-
"""
@author: 
@file: auth.py
@time: 2023/12/13 17:18
@desc: 中间件
"""
from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import HttpResponse, redirect


class AuthMiddleware(MiddlewareMixin):
    """ 中间件 """
    def process_request(self, request):
        # 0.排除那些不需要登陆就能访问的页面

        if request.path_info in ["/login/", "/image/code/"]:
            return

        # 1.读取当前访问的用户的session信息,如过能读到.说明已登陆
        info_dict = request.session.get('info')
        if info_dict:
            return

        # 2.没有登陆过,返回
        return redirect('/login/')



